package com.guit.demo.client.login;

import com.google.inject.Inject;

import com.guit.demo.client.login.LoginPresenter.LoginBinder;
import com.guit.demo.client.main.MainPresenter;
import com.guit.junit.GuitTest;

import static junit.framework.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class TestLoginPresenter extends GuitTest {

  @Inject
  LoginPresenter presenter;

  @Override
  protected void configure() {
    mock(LoginBinder.class);
    mock(MainPresenter.class);
  }

  @Override
  @Before
  public void setUp() {
    super.setUp();
    presenter.go(null);
  }

  @Test
  public void testClear() {
    presenter.clear$click();
    assertNull(presenter.username.getText());
    assertNull(presenter.password.getText());
    assertNull(presenter.message.getInnerText());
  }

  @Test
  public void testFailureKeyPress() {
    presenter.username.setText("bad");
    presenter.password.setText("guy");
    presenter.login$username$password$keyPress();
    assertEquals(presenter.message.getInnerText(), LoginPresenter.ERROR_LOGGIN_IN);
  }

  @Test
  public void testFailureLogin() {
    presenter.username.setText("bad");
    presenter.password.setText("guy");
    presenter.login$click();
    assertEquals(presenter.message.getInnerText(), LoginPresenter.ERROR_LOGGIN_IN);
  }

  @Test
  public void testSuccessKeyPress() {
    presenter.username.setText("admin");
    presenter.password.setText("admin");
    presenter.login$username$password$keyPress();
    assertEquals(presenter.message.getInnerText(), LoginPresenter.YOU_LOGGED_IN);
  }

  @Test
  public void testSuccessLogin() {
    presenter.username.setText("admin");
    presenter.password.setText("admin");
    presenter.login$click();
    assertEquals(presenter.message.getInnerText(), LoginPresenter.YOU_LOGGED_IN);
  }
}
